package com.scau.XFourPOS.action;

import java.util.List;

import com.scau.XFourPOS.model.ProductCategory;
import com.opensymphony.xwork2.ModelDriven;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.scau.XFourPOS.service.ProductCategoryService;
import com.scau.XFourPOS.utils.PageUtils;

/**
 * 类名：ProductCategoryAction 类描述：商品控制器 创建人：庄祥鹏
 * */
@Controller
@ParentPackage("struts-default")
public class ProductCategoryAction extends BaseAction implements ModelDriven<ProductCategory> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private ProductCategoryService productCategoryService;
	public ProductCategory productCategory = new ProductCategory();

	/**
	 * 得到数据列表
	 */
	@Action("productCategoryGridAction")
	public void grid() {
		PageUtils<ProductCategory> pageUtils = new PageUtils<ProductCategory>(page, rows, sort,
				order);
		List<ProductCategory> list = productCategoryService.loadAllByPage(pageUtils)
				.getResult();
		long total = pageUtils.getTotalCount();
		writeJson(total, list);
	}

	/**
	 * 添加操作
	 */
	@Action("productCategorySaveAction")
	public void save() {
		Json result = new Json();
		try {
			productCategoryService.saveEntity(productCategory);
			result.setSuccess(true);
			result.setMsg("添加产品类别成功");
		} catch (Exception e) {
			result.setMsg("添加产品类别失败");
		}
		writeJson(result);
	}
	/**
	 * 删除操作
	 */
	@Action("productCategoryDeleteAction")
	public void delete() {
		Json result = new Json();
		try {
			productCategoryService.deleteEntityById(id);
			result.setSuccess(true);
			result.setMsg("删除产品类别成功");
		} catch (Exception e) {
			result.setMsg("删除产品类别失败");
		}
		writeJson(result);
	}
	/**
	 * 修改操作
	 */
	@Action("productCategoryUpdateAction")
	public void update() {
		Json result = new Json();
		try {
			productCategoryService.updateEntity(productCategory);
			result.setSuccess(true);
			result.setMsg("修改产品类别成功");
		} catch (Exception e) {
			result.setMsg("添加产品类别失败");
		}
		writeJson(result);
	}

	@Override
	public ProductCategory getModel() {
		return productCategory;
	}

}
